<template>
  <div>
    <x-header id="header" :left-options="{backText: ''}">提现明细</x-header>
    <div class="cash-main main-header">
      <div class="cash">
        <div class="title">提现金额</div>
        <!--<div class="amount">0.00</div>-->
        <x-input class="amount" v-model="money" :show-clear="false" :max="4" text-align="center">0.00</x-input>
        <div class="to">
          <div class="to-name">到帐银行卡</div>
          <div class="to-code" v-if="bankCode">尾号{{bankCode}}</div>
          <x-button class="to-add" mini v-else @click.native="goBank">增加</x-button>
        </div>
        <div class="tips">温馨提示：提现在4个工作日内到账，如有疑问可联系客户经理或客服</div>
        <div class="save">
          <x-button class="save-button" @click.native="cashHandle">提交</x-button>
        </div>
      </div>
      <div class="cash-hotline" v-if="hotLine">客服热线：{{hotLine}}</div>
    </div>
  </div>
</template>

<script>
import { cookie } from 'vux'
import { cash,getUserDetail } from '@/api/user'

export default {
  name: 'cash',
  data () {
    return {
      hotLine: '',
      bankCode: '',
      cid: '',
      money: ''
    }
  },
  methods: {
    cashHandle() {
      if (!this.money) {
        this.$vux.toast.show({
          text: '缺少金额',
          type: 'cancel'
        })
      } else {
        cash({cid:this.cid,money: parseInt(this.money)}).then(() =>{
          this.$vux.toast.show({
            text: '提交成功',
            type: 'success'
          })
          setTimeout(() => {
            this.$router.back(-1)
          }, 1500)
        })
      }
    },
    goBank () {
      this.$router.push('bank')
    }
  },
  mounted () {
    getUserDetail(this.globalData.cid).then( data => {
      this.detail = data
      cookie.set('userInfo', JSON.stringify(data))
      this.bankCode = data.bankCardNumber.substring(data.bankCardNumber.length - 4)
      this.cid = data.id
    })
    let config = cookie.get('config') || JSON.parse(cookie.get('config'))
    this.hotLine = config.customerService

  }
}
</script>

<style scoped>

</style>
